package com.saxon.blog.service.Blog;


import com.saxon.blog.Dao.Blog.BlogDao;
import com.saxon.blog.Dao.Blog.BlogTypeDao;
import com.saxon.blog.pojo.BlogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BlogTypeServiceImpl implements BlogTypeService {
    private BlogTypeDao blogTypeDao;
    private BlogDao blogDao;

    @Autowired
    public void setBlogTypeDao (BlogTypeDao blogTypeDao) {
        this.blogTypeDao = blogTypeDao;
    }

    @Autowired
    public void setBlogDao (BlogDao blogDao) {
        this.blogDao = blogDao;
    }

    @Override
    public List<BlogType> QueryAllType () {

        return blogTypeDao.QueryAllType ();
    }

    @Override
    public BlogType QueryBlogTypeById (int id) {
        return blogTypeDao.QueryBlogTypeById (id);
    }

    @Override
    public BlogType QueryBlogTypeByName (String blogTypeName) {
        return blogTypeDao.QueryBlogTypeByName (blogTypeName);
    }

    @Transactional
    @Override
    public int insertBlogType (String typeName) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("typeName", typeName);
        map.put ("addTime", new Date ());
        return blogTypeDao.insertBlogType (map);
    }

    @Transactional
    @Override
    public int deleteBlogType (int id) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("type_id", id);
        blogDao.updateBlog (map);
        return blogTypeDao.deleteBlogType (id);
    }

    @Transactional
    @Override
    public int updateBlogType (String typeName, int id) {
        Map<String, Object> map = new HashMap<> ();
        map.put ("typeName", typeName);
        map.put ("id", id);
        return blogTypeDao.updateBlogType (map);
    }
}
